package xinxin.com.InterpreterPattern;

import xinxin.com.InterpreterPattern.context.PlayContext;
import xinxin.com.InterpreterPattern.expression.Expression;
import xinxin.com.InterpreterPattern.expression.impl.Note;
import xinxin.com.InterpreterPattern.expression.impl.Scale;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/9 21:01
 */
public class InterpreterPattern {
    public static void main(String[] args) {
        PlayContext context = new PlayContext();

        System.out.println("上海滩：");
        context.setText("O 2 E 0.5 A 3 E 0.5 G 0.5 D 3 E 0.5 G 0.5 A 0.5 O 3 C 1 O 2 A 0.5 G 1 C 0.5 E 0.5 D 3");

        Expression expression = null;
        while (context.getText().length() > 0) {
            System.out.println("context:" + context.getText() + "|");
            String str = context.getText().substring(0, 1);
            switch (str) {
                case "O":
                    expression = new Scale();
                    break;
                case "C":
                case "D":
                case "E":
                case "F":
                case "A":
                case "B":
                case "P":
                    expression = new Note();
                    break;
            }
            expression.Interpret(context);
        }
    }
}
